<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        div{width: 20px;height: 20px;background: red;position: absolute;left:0;top:0;color: #fff;text-align: center;line-height: 20px;}
    </style>
</head>
<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
    <div>9</div>
</body>
<script>
    var adiv = document.querySelectorAll("div");

    document.onmousemove = function(eve){
        var e = eve || window.event;

        // 先从最后一个元素开始，每一个元素都找前一个元素的位置
        for(var i=adiv.length-1;i>0;i--){
            adiv[i].style.left = adiv[i-1].offsetLeft + "px";
            adiv[i].style.top = adiv[i-1].offsetTop + "px";
        }

        // 第一个元素找鼠标的位置
        adiv[0].style.left = e.pageX + "px";
        adiv[0].style.top = e.pageY + "px";

    }
</script>
</html>